package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceListDTO;
import com.zzyl.dto.ResponseDto;
import com.zzyl.entity.Resource;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;



    @ApiOperation("3.4 资源列表")
    @PostMapping("/list")
    public ResponseResult<List<Resource>> list(@RequestBody ResourceListDTO dto){
        List<Resource> list = resourceService.list(dto);
        return ResponseResult.success(list);
    }

    @ApiOperation("3.7 资源树形")
    @PostMapping("/tree")
    public ResponseResult<TreeVo> tree(){
        TreeVo treeVo = resourceService.tree();
        return ResponseResult.success(treeVo);
    }

    @PutMapping
    private ResponseResult add(@RequestBody ResponseDto dto  ){
        resourceService.add(dto);
        return ResponseResult.success();

    }
}
